<?php
/* @var $this UserController */
/* @var $dataProvider CActiveDataProvider */

$this->breadcrumbs=array(
	'Anggota',
);

$this->pageTitle=Yii::app()->name . " - Semua Anggota";
?>

<div class="kolom-1">
	<h1 class="judul-halaman">SEMUA ANGGOTA UKM BIMBEL STIS</h1>
	<div class="latar-putih" align="left">
		<div align="left" class="agencyr besar" style="margin-left:10px; margin-bottom:10px;">
			Pencarian Cepat: 
			<?php
				$autoCompleteId = 'userautocomplete';
				$this->widget('zii.widgets.jui.CJuiAutoComplete',
				   array(
					   'id'        => $autoCompleteId,
					   'name'      => 'term',
					   'sourceUrl' => $this->createUrl('lookup'),
					   'options'   => array('minLength' => 2,),
					   'htmlOptions'=> array(
						   'style'     => 'height:25px;',
						   'onKeyPress' => '{if (event.keyCode==13) window.open("?pencarian="+this.value,"_self")}',
					   ),
				   )
				);
				Yii::app()->clientScript->registerScript('userAutoComplete',"jQuery('#$autoCompleteId').data('autocomplete')._renderItem = function( ul, item ) {
				return $('<li></li>')
				.data('item.autocomplete', item)
				.append('<a class=\'userautocompletelink\' href=\''+item.link+'\'><div align=\'center\'><img src=\''+item.image+'\'/></div><h1>'+item.label+'<h2>'+item.nim+'<h2></h1></a>')
				.appendTo(ul);};
				"
				,CClientScript::POS_READY); 
			?>
		</div>
		<?php
			$pencarian = "";
			function transform_HTML($string, $length = NULL){
				$string = trim($string);
				$string = utf8_decode($string);
				$string = htmlentities($string, ENT_NOQUOTES);
				$string = str_replace("\"", "&#34;", $string);
				$string = str_replace("#", "&#35;", $string);
				$string = str_replace("$", "&#36;", $string);
				$string = str_replace("%", "&#37;", $string);
				$string = str_replace("&", "&#38;", $string);
				$string = str_replace("'", "&#39;", $string);
				$string = str_replace("(", "&#40;", $string);
				$string = str_replace(")", "&#41;", $string);
				$string = str_replace("*", "&#42;", $string);
				$string = str_replace("+", "&#43;", $string);
				$string = str_replace(",", "&#44;", $string);
				$string = str_replace("-", "&#45;", $string);
				$string = str_replace("/", "&#47;", $string);
				$string = str_replace(":", "&#58;", $string);
				$string = str_replace(";", "&#59;", $string);
				$string = str_replace("<", "&#60;", $string);
				$string = str_replace("=", "&#61;", $string);
				$string = str_replace(">", "&#62;", $string);
				$string = str_replace("?", "&#63;", $string);
				$string = str_replace("@", "&#64;", $string);
				$string = str_replace("[", "&#91;", $string);
				$string = str_replace("]", "&#93;", $string);
				$string = str_replace("^", "&#94;", $string);
				$string = str_replace("_", "&#95;", $string);
				$string = str_replace("`", "&#96;", $string);
				$string = str_replace("{", "&#123;", $string);
				$string = str_replace("|", "&#124;", $string);
				$string = str_replace("}", "&#125;", $string);
				$string = str_replace("~", "&#126;", $string);
				
				$length = intval($length);
				if ($length > 0){
					$string = substr($string, 0, $length);
				}
				return $string;
			}
			if(isset($_GET['pencarian'])){
				$pencarian = transform_HTML($_GET['pencarian']);
			}
			$sqlStatement = "SELECT * FROM user where nama like '%".$pencarian."%' or username like '%".$pencarian."%'";
			$totalhalaman = Yii::app()->db->createCommand("SELECT COUNT(*) FROM user where nama like '%".$pencarian."%' or username like '%".$pencarian."%'")->queryScalar();
			$dataProvider=new CSqlDataProvider($sqlStatement,array(
			   'keyField' => 'id',
				'sort' => array(
					'attributes' => array(
						'nama','username', 'angkatan_id'
					),
					'defaultOrder' => array(
						'nama' => CSort::SORT_ASC, //default sort value
					),
				),
			   'totalItemCount'=>$totalhalaman,
			   'pagination'=>array(
				   'pageSize'=>20,
				),
			 ));
			$page = new CPagination($totalhalaman);
			$page->pageSize = 20;
			$i=0;
			if(count($dataProvider->data)==0) echo "<i>Tidak Ditemukan Hasil</i>";
			foreach ($dataProvider->data as $id=>$user){
				if($i==$page->pageSize) $i=0;
				if($i%4==0) echo "<div class='clear'></div>";
			?>
				<div class="user-foto">
					<a href="<?php echo Yii::app()->createUrl('/user/view', array('id'=>$user['id'])); ?>">
					<img src="<?php echo $user['foto']==null ? Yii::app()->request->baseUrl.'/images/profil/default.png' : Yii::app()->request->baseUrl.'/images/profil/'.$user['foto'].''; ?>" alt="user-foto" />
					<div align="center" class="user-nama agencyr besar"><?php echo $user['nama']; ?></div>
					</a>
				</div>
			
			<?php 
				$i++;
			  } ?>
				<br/><div class='clear'></div><br/><br/>
				<span class="agencyr besar">
			<?php
			  $this->widget('CLinkPager',array(
				'pages'=>$page,
				'htmlOptions' => array('style'=>'font-family:AgencyR; font-size:16px;'),
				'maxButtonCount'=>5,
			));
			?>
				</span>
	</div>
</div>
